/*
class MyArray<T> {
    public T[] array = (T[])new Object[10];//1
    public T getPos(int pos) {
        return this.array[pos];
    }
    public void setVal(int pos,T val) {
        this.array[pos] = val;
    }
}
class TestDemo {
    public static void main(String[] args) {
        MyArray<String> myArray = new MyArray<>();//2
        myArray.setVal(0,"10");
        myArray.setVal(1,"12");
        String ret = myArray.getPos(1);//3
        System.out.println(ret);
    }
}*/

/**
 * 错误示例
 * @param <T>
 */
class MyArray1<T> {
    public Object[] array = new Object[10];
    public T getPos(int pos) {
        return (T)this.array[pos];
    }
    public void setVal(int pos,T val) {
        this.array[pos] = val;
    }
    public T[] getArray() {
        return (T[])array;
    }
    public static void main(String[] args) {
        MyArray1<Integer> myArray1 = new MyArray1<>();
        myArray1.setVal(0,10);
        myArray1.setVal(1,12);
        //myArray1.setVal(1,"bit");
        Integer ret = myArray1.getPos(1);
        System.out.println(ret);
        Integer[] strings = myArray1.getArray();
    }
}
